/****************************************************************************
*                                                                           *
* drawstate.cpp 								                            *
*                                                                           *
* ALaRI 2008												                *
*                                                                           *
****************************************************************************/

/****************************************************************************
* Includes										                            *
****************************************************************************/
#include "drawmanager.h"
#include "drawstate.h"
#include "drawshape.h"

/****************************************************************************
* CDrawState													 			*
****************************************************************************/

/****************************************************************************
* CDrawStateIdle												 			*
****************************************************************************/
void CDrawStateIdle::processEvent(CDrawManager *pDrawManager,  QEvent *pEvent)
{
	assert(NULL != pEvent);
	assert(NULL != pDrawManager);
	
	if (pEvent->type() == QEvent::MouseButtonPress)
	{
		QMouseEvent *pMouseEvent = dynamic_cast<QMouseEvent *> (pEvent); 
		pDrawManager->selectShape(pMouseEvent->pos());
	}
}

/****************************************************************************
* CDrawStateRect												 			*
****************************************************************************/
void CDrawStateRect::processEvent(CDrawManager *pDrawManager,  QEvent *pEvent)
{
	assert(NULL != pEvent);
	assert(NULL != pDrawManager);
	QMouseEvent *pMouseEvent;

	switch(pEvent->type())
	{
	case QEvent::MouseButtonPress :
		pMouseEvent = dynamic_cast<QMouseEvent *> (pEvent); 
		m_pointStart = pMouseEvent->pos();
		m_pointEnd = pMouseEvent->pos();
		pDrawManager->addShape(new CDrawRect(QRect(m_pointStart, m_pointEnd), 
			pDrawManager->getPenColor(), pDrawManager->getPenWidth()));
		break;
	case QEvent::MouseMove :
		pMouseEvent = dynamic_cast<QMouseEvent *> (pEvent);
		m_pointEnd = pMouseEvent->pos();
		pDrawManager->reshape(m_pointEnd, -1);
		break;
	}
}

/****************************************************************************
* CDrawStateLine												 			*
****************************************************************************/
void CDrawStateLine::processEvent(CDrawManager *pDrawManager,  QEvent *pEvent)
{
	assert(NULL != pEvent);
	assert(NULL != pDrawManager);
	QMouseEvent *pMouseEvent;

	switch(pEvent->type())
	{
	case QEvent::MouseButtonPress :
		pMouseEvent = dynamic_cast<QMouseEvent *> (pEvent); 
		m_pointStart = pMouseEvent->pos();
		m_pointEnd = pMouseEvent->pos();
		pDrawManager->addShape(new CDrawLine(QLine(m_pointStart, m_pointEnd), 
			pDrawManager->getPenColor(), pDrawManager->getPenWidth()));
		break;
	case QEvent::MouseMove :
		pMouseEvent = dynamic_cast<QMouseEvent *> (pEvent);
		m_pointEnd = pMouseEvent->pos();
		pDrawManager->reshape(m_pointEnd, -1);
		break;
	}
}

/****************************************************************************
* CDrawStateEllipse												 			*
****************************************************************************/
void CDrawStateEllipse::processEvent(CDrawManager *pDrawManager,  QEvent *pEvent)
{
	assert(NULL != pEvent);
	assert(NULL != pDrawManager);
	QMouseEvent *pMouseEvent;

	switch(pEvent->type())
	{
	case QEvent::MouseButtonPress :
		pMouseEvent = dynamic_cast<QMouseEvent *> (pEvent); 
		m_pointStart = pMouseEvent->pos();
		m_pointEnd = pMouseEvent->pos();
		pDrawManager->addShape(new CDrawEllipse(QRect(m_pointStart, m_pointEnd), 
			pDrawManager->getPenColor(), pDrawManager->getPenWidth()));
		break;
	case QEvent::MouseMove :
		pMouseEvent = dynamic_cast<QMouseEvent *> (pEvent);
		m_pointEnd = pMouseEvent->pos();
		pDrawManager->reshape(m_pointEnd, -1);
		break;
	}
}

/****************************************************************************
* CDrawStatePoint												 			*
****************************************************************************/
void CDrawStatePoint::processEvent(CDrawManager *pDrawManager,  QEvent *pEvent)
{
	assert(NULL != pEvent);
	assert(NULL != pDrawManager);
	QMouseEvent *pMouseEvent;

	switch(pEvent->type())
	{
	case QEvent::MouseButtonPress :
		pMouseEvent = dynamic_cast<QMouseEvent *> (pEvent); 
		pDrawManager->addShape(new CDrawPoint(pMouseEvent->pos(), Qt::blue, 5));
		break;
	}
}
/****************************************************************************
* End of file																*
****************************************************************************/